# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Matt Smith <mcs@darkregion.net>
# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: Iggy Jackson <iggy@theiggy.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=nsd
pkgver=4.8.0
pkgrel=0
pkgdesc="Authoritative only, high performance and simple DNS server"
url="https://www.nlnetlabs.nl/projects/nsd"
arch="all"
license="BSD-3-Clause"
makedepends="openssl-dev>3 libevent-dev"
install="$pkgname.pre-install $pkgname.pre-upgrade"
subpackages="$pkgname-doc $pkgname-dbg $pkgname-openrc $pkgname-bash-completion"
pkgusers="nsd"
pkggroups="nsd"
source="https://www.nlnetlabs.nl/downloads/nsd/nsd-$pkgver.tar.gz
	nsd.initd
	config.patch
	tsig-openssl.patch
	"
options="!check"

# secfixes:
#   4.3.4-r0:
#     - CVE-2020-28935

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--sbindir=/usr/sbin \
		--mandir=/usr/share/man \
		--with-user=nsd \
		--with-pidfile=/run/nsd/nsd.pid \
		--with-xfrdir=/var/db/nsd \
		--enable-ratelimit \
		--enable-ratelimit-default-is-off \
	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname

	install -d "$pkgdir"/usr/share/doc/$pkgname
	cp -a "$builddir"/doc/* "$builddir"/contrib \
		"$pkgdir"/usr/share/doc/$pkgname/
	rm "$pkgdir"/usr/share/doc/nsd/contrib/nsd.service

	mkdir -p "$pkgdir"/usr/share/bash-completion/completions
	mv "$pkgdir"/usr/share/doc/nsd/contrib/autocomplete_nsd-control.bash \
		"$pkgdir"/usr/share/bash-completion/completions/nsd-control

	install -d -m 755 -o nsd -g nsd "$pkgdir"/var/db/nsd
	rm -fr "$pkgdir"/run
}

sha512sums="
13c9cffffe6adfcbabf744ee2effebe6ae265d83476345a1edb60dc9c6d7f838a5e239e9b18e667924e5e76b74b2caac63818fcaecf7f0fa651ff21736174a46  nsd-4.8.0.tar.gz
bc2b27d98b99db067c7c4b152ee40ae81b8ee66989f873ca0c21f57333c3734bb342866f68d5837f10bb56cb598fafc794095c02b8bc97ef6dace450cae526a6  nsd.initd
5b192f2151114d1853fb17f89324d9cc7ec16aa4d057c4f86b81ce8385b69eeb128df737e12597705c2acd33cdfd5857ed3234e4be153a36ba1dcf4175232701  config.patch
3a9085320ceb4b63d2cada23f730f515b306d641c782a0b1b0b9c4cef0e473f5e6accbce8bbbfdb2ce0275adb947f5705aa3e0f1e4809775e2910173456b7e5b  tsig-openssl.patch
"
